home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************\
- * *
- * Programmed By : Robert Goshko CIS : [76645,3335] *
- * *
- * These three functions allow you to write directly to the screen. Something *
- * you must do, in order to use the extended text modes supported by EGA and *
- * VGA cards alike. *
- * *
- * The first function, sprint, is almost identical to cprintf, except there *
- * are five control variables before the string to be printed, they are: *
- * *
- * sprint( xloc, ylox, fgcol, bgcol, blink flag, string... *
- * xloc - the x location on the screen. *
- * yloc - the y location on the screen. *
- * fgcol - the foreground color (0-15). *
- * bgcol - the background color (0-7). *
- * blink flag - 0 for non-blinking text, 1 for blinking text. *
- * string - the string you want printed eg. (" Balance = %5.2d ",bal) *
- * *
- * The second two are used to save and restore the screen much like the *
- * gettext and puttext functions, except now you can access past line 25 of *
- * the standard screen. *
- * *
- * Freeware from Axis Development *
- * *
- \*****************************************************************************/
-
- #include <stdarg.h>
-
- #define SCR_SEG 0xB800 /* Segment of video memory */
- #define COL 80 /* Number of columns on screen */
- #define ROW 50 /* Number of rows on screen (43 EGA/50 VGA) */
- #define NULL 0x00 /* Null Flag */
-
- int sprint(int x, int y, int f, int b, int bl, char *fmt, ... )
- {
- void far *daddress; /* Physical Address of Data */
- void far *aaddress; /* Physical Address of Attribute */
- unsigned buf_seg, buf_off, attr_seg, attr_off;
- va_list argptr; /* Argument list pointer */
- char str[140]; /* Buffer to build sting into */
- int i, scr_off, attr, cnt;
-
- if( x < 1 || x > COL ) /* Check for legal screen values */
- return(-1);
- if( y < 1 || y > ROW )
- return(-1);
-
- va_start( argptr, format ); /* Initialize va_ functions */
- cnt = vsprintf( str, fmt, argptr ); /* prints string to buffer */
- va_end( argptr ); /* Close va_ functions */
-
- daddress = ( void far *)str; /* Determine physical address (data) */
- buf_seg = FP_SEG(daddress); /* Get segment (data) */
- buf_off = FP_OFF(daddress); /* Get offset (data) */
-
- scr_off = ( ( x * 2 ) - 2 ) + ( ( y * ( 2 * COL ) ) - ( 2 * COL ) );
- /* Compute x & y location in memory */
-
- attr = 0;
-
- if( bl == 1 ) /* Check for blink */
- attr += 128; /* If blink then set bit 8 */
- if( b > -1 && b < 8 ) /* Check for valid background color */
- attr = attr + ( 16 * b ); /* If valid, set color */
- else /* If not a valid background color */
- return(-1); /* Return -1 */
- if( f > -1 && f < 16 ) /* Check for valid foreground color */
- attr = attr + f; /* If valid, set color */
- else /* If not a valid foreground color */
- return(-1); /* Return -1 */
-
- aaddress = (void far *)&attr; /* Determine phisical address (attr) */
- attr_seg = FP_SEG(aaddress); /* Get segment (attr) */
- attr_off = FP_OFF(aaddress); /* Get offset (attr) */
-
- for( i = 0 ; i < strlen(str) ; i++) /* Set loop to size of string */
- {
- movedata( buf_seg, buf_off+i, SCR_SEG, scr_off + ( i * 2 ), 1);
- /* Copy data to screen memory */
- movedata( attr_seg, attr_off, SCR_SEG, scr_off + ( ( i * 2 ) + 1 ), 1);
- /* Copy attribute to screen memory */
- }
- return(cnt); /* Return number of bytes (data) printed */
- }
-
- int Save_Scr(int Top_Col, int Top_Row, int Bot_Col, int Bot_Row, char *Stor_Buf)
- {
-
- void far *address; /* Physical Address of Data Buffer */
- unsigned BUF_seg, BUF_off;
- char BUF[(COL*2)+10]; /* Buffer to build sting into */
- int i, scr_off, Rows, Cols;
-
- if( Top_Col < 1 || Bot_Col > COL ) /* Check for legal screen values */
- return(-1);
- if( Top_Row < 1 || Bot_Row > ROW )
- return(-1);
-
- if(Bot_Col < Top_Col) /* Check for legal values */
- return(-1);
- if(Bot_Row < Top_Row)
- return(-1);
-
- address = ( void far *)BUF; /* Determine physical address (buffer) */
- BUF_seg = FP_SEG(address); /* Get segment (buffer) */
- BUF_off = FP_OFF(address); /* Get offset (buffer) */
-
- Rows = ( Bot_Row - Top_Row ) + 1; /* Compute number of rows to save */
- Cols = (( Bot_Col - Top_Col ) + 1 ) * 2;
- /* Get lenght of each row (char&attr)*/
- Stor_Buf[0] = NULL; /* Clear Storage buffer */
-
- for( i = 0 ; i < Rows ; i++ )
- {
- scr_off=(( Top_Col * 2 ) - 2 ) + ((( Top_Row + i ) * ( COL * 2 )) - ( COL * 2 ));
- /* Compute offset of row */
- movedata( SCR_SEG, scr_off, BUF_seg, BUF_off, Cols );
- /* Move row into buffer memory */
- BUF[Cols] = NULL; /* Mark end of row */
- strcat( Stor_Buf, BUF ); /* Move row into storage memory */
- }
-
- return(0);
- }
-
- int Load_Scr(int Top_Col, int Top_Row, int Bot_Col, int Bot_Row, char *Stor_Buf)
- {
-
- void far *address; /* Physical Address of Data Buffer */
- unsigned BUF_seg, BUF_off;
- int i, scr_off, Rows, Cols;
-
- if( Top_Col < 1 || Bot_Col > COL ) /* Check for legal screen values */
- return(-1);
- if( Top_Row < 1 || Bot_Row > ROW )
- return(-1);
-
- if(Bot_Col < Top_Col) /* Check for legal box values */
- return(-1);
- if(Bot_Row < Top_Row)
- return(-1);
-
- address = ( void far *)Stor_Buf; /* Determine physical address (buffer) */
- BUF_seg = FP_SEG(address); /* Get segment (buffer) */
- BUF_off = FP_OFF(address); /* Get offset (buffer) */
-
- Rows = ( Bot_Row - Top_Row ) + 1; /* Number of rows to load */
- Cols = (( Bot_Col - Top_Col ) + 1 ) * 2;
- /* Length of each row (char + attr) */
-
- for( i = 0 ; i < Rows ; i++ )
- {
- scr_off=(( Top_Col * 2 ) - 2 ) + ((( Top_Row + i ) * ( COL * 2 )) - ( COL * 2 ));
- /* Compute offset of row */
- movedata( BUF_seg, BUF_off + ( Cols * i ), SCR_SEG, scr_off, Cols );
- /* Load row into screen memory */
- }
-
- return(0);
- }